package com.dios.mirage.component.fields;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.TouchEvent;

import com.dios.mirage.component.view.View;

public class HoverField extends FocusableField {

	View view;
	String target;
	String desc;
	String text;
	private boolean isTouchOutside;

	public HoverField(String text, String desc, String slide, View view) {
		super(null, Field.FOCUSABLE);
		this.view = view;
		this.target = slide;
		this.text = text;
		this.desc = desc;
	}

	/*
	 * public void draw(String hoverString) { onHoverBitmap = bitmap; Graphics
	 * graphics = Graphics.create(onHoverBitmap); int xOffset =
	 * (onHoverBitmap.getWidth() - Font.getDefault().getAdvance( hoverString)) /
	 * 2; int yOffset = (onHoverBitmap.getHeight() -
	 * Font.getDefault().getHeight()) / 2;
	 * 
	 * graphics.setColor(Color.WHITE); graphics.drawText(hoverString, xOffset,
	 * yOffset); }
	 * 
	 * public void focusChanged(Field field, int eventType) { if(eventType ==
	 * FOCUS_GAINED){ System.out.println("Hover"); }else if(eventType ==
	 * FOCUS_LOST){ System.out.println("Unhover"); } }
	 */

	protected boolean touchEvent(TouchEvent touchEvent) {
		isTouchOutside = touchEvent.getX(1) < 0
				|| touchEvent.getX(1) > getWidth() || touchEvent.getY(1) < 0
				|| touchEvent.getY(1) > getHeight();
		//view.setContent(target, text, desc);
		return super.touchEvent(touchEvent);
	}

	protected boolean navigationClick(int status, int time) {
		if (!isTouchOutside)
			view.setContent(target, text, desc);
		return true;
	}

}
